package com.hhs.storage.bean;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.TableField;
import com.hhs.storage.util.SysUtil;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author hhs
 * @since 2023-01-04
 */
@Data
public class BusinessDocument implements Serializable {

    private static final long serialVersionUID = 1L;
    public static final int STATUS_CREATE = 0;//待下单
    public static final int STATUS_ORDERED = 1;//已下单
    public static final int STATUS_COMPLETE = 2;//已完成

    private String id;

    /**
     * 所属合同id
     */
    private String contractId;
    @TableField(exist = false)
    private Contract contract;

    /**
     * 客户公司id
     */
    private String customerId;
    @TableField(exist = false)
    private Comsumer comsumer;

    private String modelType;
    /**
     * 数量
     */
    private BigDecimal num;

    /**
     * 单位
     */
    private String unit;
    private Integer state;
    /**
     * 创建人
     */
    private String creator;
    /**
     * 备注
     */
    private String remark;

    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    /**
     * 单位文本
     *
     * @return
     */
    public String getUnitName() {
        return SysUtil.UNIT_MAP.get(this.unit);
    }

    public String getModelTypeName() {
        List<TypeDic> list = SysUtil.MODEL_TYPE_LIST;
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getId().equals(this.modelType)) {
                return list.get(i).getName();
            }
        }
        return null;
    }

    public String getStateName() {
        return SysUtil.BUSINESS_DOCUMENT_STATE_MAP.get(this.state);
    }
}
